feat(ai): project rules — load AGENTS.md into the agent's system prompt - #21
Merged
Conversation
Drop an AGENTS.md (or CLAUDE.md / .cursorrules) in a repo and the agent follows it from turn one. Loaded once per run into the cached system block (byte-stable, so it rides the prompt cache), multi-root aware, first-present-file wins, capped at 16KB. A quiet timeline chip shows when rules are active. - projectRules.js: pure loader (file reading injected -> unit-testable) - agent.js: fold rules.text into the system prompt + the indicator chip - test/projectRules.test.js: 10 cases + a real-filesystem smoke test - docs/PROJECT-RULES.md: how it works, precedence, and the trust model Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds “project rules” support to the LevelCode AI agent by loading repo-local rules files (e.g. AGENTS.md) once per agent run and injecting them into the agent’s system prompt, making repository conventions effective from the first turn.
Changes:
- Introduces a pure, unit-testable rules loader (
loadProjectRules) with filename precedence and per-file size capping. - Integrates project rules into the agent’s cached system prompt and surfaces an activity-timeline chip showing which rules files were loaded.
- Adds unit tests and end-user documentation for behavior, precedence, and trust model.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| extensions/levelcode-ai/projectRules.js | Implements rules discovery/loading/formatting for injection into the system prompt. |
| extensions/levelcode-ai/agent.js | Loads project rules once per run, appends them to the system prompt, and posts a “project rules” timeline chip. |
| extensions/levelcode-ai/test/projectRules.test.js | Adds unit tests covering discovery, precedence, multi-root labeling, skipping empty files, truncation, and error handling. |
| docs/PROJECT-RULES.md | Documents how rules are discovered, applied, labeled in multi-root workspaces, and bounded for safety/cost. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… test - projectRules: a folder entry with a root but no name produced "undefined/AGENTS.md" in multi-root labels; fall back to path.basename(f.root). - test: add the real-filesystem smoke test the doc referenced (writes an on-disk AGENTS.md and reads it back) — it was only run inline before — plus a case for the name fallback. 12 cases now. - docs: describe the test coverage accurately. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Project rules — drop an
AGENTS.md(orCLAUDE.md/.cursorrules) in a repo and the agent follows it from turn one.projectRules.js— pure loader (loadProjectRules(folders, readFile)); file reading is injected as a callback, so it's unit-testable without a filesystem. Multi-root aware, first-present-file wins, empty files skipped, capped at 16KB.agent.js— folds the rules into the cached system block (byte-stable per run → rides the prompt cache at ~0.1×), and posts a quiet📋 project rules · AGENTS.mdchip so you can see it's active.test/projectRules.test.js— 10 cases (discovery, alias fallback, first-present-wins, multi-root, empty-skip, truncation, throwing reader) + a real-filesystem smoke test.docs/PROJECT-RULES.md— how it works, precedence, and the trust model (rules yield to a direct request; they can't disable the host-side safety gates).All 13 test files pass.
🤖 Generated with Claude Code